package com.ysu.zyw.service;

import com.ysu.zyw.dao.BlogArticleMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.annotation.security.RolesAllowed;
import javax.servlet.http.HttpServletRequest;
import java.io.File;

/**
 * Created by zhang_yao_wu1993 on 15/4/27.
 *
 * @author by Zerur
 */
@Service("blogArticleService")
public class BlogArticleService {
    private BlogArticleMapper blogArticleMapper;

    public BlogArticleMapper getBlogArticleMapper() {
        return blogArticleMapper;
    }

    @SuppressWarnings("all")
    @Resource
    public void setBlogArticleMapper(BlogArticleMapper blogArticleMapper) {
        this.blogArticleMapper = blogArticleMapper;
    }


    @Transactional
    @RolesAllowed("ROLE_ADMIN")
    public void deleteArticle(String uuid, HttpServletRequest request) {
        String wizHtmlPath = request.getSession().getServletContext().getRealPath("/WEB-INF/view/wiz-html");
        File wizHtmlFile = new File(wizHtmlPath + "/" + uuid + ".jsp");
        if(wizHtmlFile.exists()) {
            wizHtmlFile.delete();
        }

        blogArticleMapper.deleteBlogArticleEntity(uuid);
    }
}
